# 自定义 chrome 下载器

from selenium import webdriver
import time
import scrapy

class AqiChromeMiddleware(object):

    def process_request(self, request, spider):
        url = request.url

        if url != "https://www.aqistudy.cn/historydata/":
            # 创建无头浏览器
            driver = webdriver.Chrome()
            # 发送请求
            driver.get(url)

            time.sleep(1)
            # 获取数据
            data = driver.page_source
            # 关闭浏览器
            driver.quit()

            return scrapy.http.HtmlResponse(

                url=request.url,
                status=200,
                body=data.encode('utf-8'),
                request=request,
                encoding='utf-8'

            )












